<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/all.conf.php');
require_once(__PHY_LIB.'/inc/page.inc.php');
require_once(__PHY_LIB.'/class/uDirector.class.php');
require_once(__PHY_LIB.'/class/uWork.class.php');

$rP = validate($_GET, 'output:u|category:n|pg:n');

/// 仅输出内容 ///
if ('content' == $rP['output']) {
	$rPager = array(
		'Sze' => 2,
		'Num' => max(1, $rP['pg']),
		'Bse' => http_build_query(array_slice($rP, 0, -1)),
	);
	$oList = new uWorkList();
	$oList->cfgWhere("category_id='{$rP['category']}'");
	$rPager['Cnt'] = $oList->countAll();
	$rPager['Max'] = ceil($rPager['Cnt']/$rPager['Sze']);
	$oList->cfgOrder('id DESC');
	$oList->load($rPager['Sze']*($rPager['Num'] - 1), $rPager['Sze']);
	while ($oOne = $oList->nextItem()) {
		$oDirector = new uDirector($oOne->get('director_1_id'), 'title');
		$oOne->set('director_1_title', $oDirector->get('title'));
		$oDirector = new uDirector($oOne->get('director_2_id'), 'title');
		$oOne->set('director_2_title', $oDirector->get('title'));
	}
	$oTpl->assign("rList", $oList->fetchArray());
	$oTpl->assign("rPager", $rPager);
	$oTpl->assign('rP', $rP);
	$oTpl->display(dirname(__FILE__).'/'.basename(__FILE__, '.php').'_content.tpl');
}
/// 首页输出 ///
else {
	$rCategorys = array(1, 2, 3, 4);
	foreach ($rCategorys as $nCategoryID) {
		$rPager = array(
			'Sze' => 2,
			'Num' => 1,
			'CategoryID' => $nCategoryID,
		);
		$oList = new uWorkList();
		$oList->cfgWhere("category_id='{$nCategoryID}'");
		$rPager['Cnt'] = $oList->countAll();
		$rPager['Max'] = ceil($rPager['Cnt']/$rPager['Sze']);
		$oList->cfgOrder('id DESC');
		$oList->load($rPager['Sze']*($rPager['Num'] - 1), $rPager['Sze']);
		while ($oOne = $oList->nextItem()) {
			$oDirector = new uDirector($oOne->get('director_1_id'), 'title');
			$oOne->set('director_1_title', $oDirector->get('title'));
			$oDirector = new uDirector($oOne->get('director_2_id'), 'title');
			$oOne->set('director_2_title', $oDirector->get('title'));
		}
		$oTpl->assign("rList{$nCategoryID}", $oList->fetchArray());
		$oTpl->assign("rPager{$nCategoryID}", $rPager);
	}
	$oTpl->display(dirname(__FILE__).'/'.basename(__FILE__, '.php').'.tpl');
}

?>
